home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / c / mount.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  2KB  |  83 lines

  1. #include <exec/memory.h>
  2. #include <clib/exec_protos.h>
  3. #include <dos/dosextens.h>
  4. #include <dos/filesystem.h>
  5. #include <clib/dos_protos.h>
  6. #include <utility/tagitem.h>
  7.  
  8. CALLENTRY /* Before the first symbol */
  9.  
  10. struct ExecBase *SysBase;
  11. struct DosLibrary *DOSBase;
  12.  
  13. static LONG tinymain(void);
  14.  
  15. LONG entry(struct ExecBase *sysbase)
  16. {
  17.     LONG error=RETURN_FAIL;
  18.     SysBase=sysbase;
  19.     DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",39);
  20.     if(DOSBase!=NULL)
  21.     {
  22.     error=tinymain();
  23.     CloseLibrary((struct Library *)DOSBase);
  24.     }
  25.     return error;
  26. }
  27.  
  28. static LONG tinymain(void)
  29. {
  30.     STRPTR args[2]={ NULL, NULL };
  31.     struct RDArgs *rda;
  32.     struct IOFileSys *iofs;
  33.     struct Process *me=(struct Process *)FindTask(NULL);
  34.     LONG error=0;
  35.  
  36.     rda=ReadArgs("FILESYS/A,DEVICE/A",(IPTR *)args,NULL);
  37.     if(rda!=NULL)
  38.     {
  39.     iofs=(struct IOFileSys *)CreateIORequest(&me->pr_MsgPort,sizeof(struct IOFileSys));
  40.     if(iofs!=NULL)
  41.     {
  42.         if(!OpenDevice(args[0],0,&iofs->IOFS,0))
  43.         {
  44.         iofs->IOFS.io_Command=FSA_MOUNT;
  45.         iofs->io_Args[0]=(IPTR)args[1];
  46.         iofs->io_Args[1]=0;
  47.         if (DoIO(&iofs->IOFS))
  48.         {
  49.             VPrintf ("Mount of %s: failed\n", (ULONG *)&args[1]);
  50.             error = RETURN_FAIL;
  51.             PrintFault(IoErr(),"Mount");
  52.         }
  53.  
  54.         /*
  55.             Don't close the device so that it has a non-zero
  56.             open count as long as it is mounted. (Whoever wants
  57.             to dismount it must close it as well).
  58.             CloseDevice(&iofs->IOFS);
  59.         */
  60.         }
  61.         else
  62.         {
  63.         VPrintf ("OpenDevice (%s) failed\n", (ULONG *)args);
  64.         error = RETURN_FAIL;
  65.         PrintFault(IoErr(),"Mount");
  66.         }
  67.  
  68.         DeleteIORequest(&iofs->IOFS);
  69.     }
  70.     else
  71.         error = RETURN_FAIL;
  72.  
  73.     FreeArgs(rda);
  74.     }
  75.     else
  76.     {
  77.     error=RETURN_FAIL;
  78.     PrintFault(IoErr(),"Mount");
  79.     }
  80.  
  81.     return error;
  82. }
  83.